/*class PopupBox
 *
 *usage a popupBox to show messages and etc
 *
 *
 *
 *since version: 0.4
 *
 */
function PopupBox(name,innerHTML)
{
    if(innerHTML)
    {
	this.innerHTML = innerHTML;
    }
    else
    {
	this.innerHTML = this.defaultInnerHTML;
    }
    if(!name)
	return null;
    this.name = name + this.defaultId;
    this.bgName = this.name+"Bg";
    this.jqueryId = "#"+this.name;
    this.jqueryBgId = this.jqueryId+"Bg";
    this.bgColor = this.defaultBgColor;
    this.bgOpacity = this.defaultBgOpacity;
    this.fadeInTime = this.defaultFadeInTime;
    this.fadeOutTime = this.defaultFadeOutTime;
    this.zInde = this.defaultZIndex;
    this.width = this.defaultWidth;
    this.height = this.defaultHeight;
}
//defaule attrs
PopupBox.prototype.defaultInnerHTML = "loading...";
PopupBox.prototype.defaultBgColor = "#000000";
PopupBox.prototype.defaultBgOpacity = "0.5";
PopupBox.prototype.defaultFadeInTime = 500;
PopupBox.prototype.defaultFadeOutTime = 300;
PopupBox.prototype.defaultZIndex = 100;
PopupBox.prototype.defaultWidth = 400;
PopupBox.prototype.defaultHeight = 300;
PopupBox.prototype.defaultId = "PopupBox";
//functions
PopupBox.prototype.html = function(html)
{
    if(!html)
    {
	return this.innerHTML;
    }
    this.innerHTML = html;
    $(this.jqueryId).html(html);
}
PopupBox.prototype.popup = function()
{
    this.__bgAdd();
    this.__boxAdd();
    $(this.jqueryBgId).fadeIn(this.fadeInTime);
    $(this.jqueryId).fadeIn(this.fadeInTime);
}
PopupBox.prototype.popoff = function()
{
    $(this.jqueryId).fadeOut(this.fadeOutTime);
    $(this.jqueryBgId).fadeOut(this.fadeOutTime);
}
PopupBox.prototype.__boxAdd = function()
{
    if($(this.jqueryId).length==0)
	$("body").append(WrapTag("div",this.name,null,null,this.innerHTML));
    else
    {
	$(this.jquerId).html(this.innerHTML);
    }
    $(this.jqueryId).css(this.__boxCSS());
}
PopupBox.prototype.__boxCSS = function()
{
    return {"width":this.width,
	    "height":this.height,
	    "z-index":this.zIndex+1,
	    "position":"absolute",
	    "top":($(window).height()-this.height)/2,
	    "left":($(window).width()-this.width)/2,
	    "display":"none",
	    "text-align":"center"};
}
PopupBox.prototype.__bgAdd = function()
{  
    if($(this.jqueryBgId).length==0)
	$("body").append(WrapTag("div",this.bgName,null,null,""));	
    $(this.jqueryBgId).css(this.__bgCSS());
}
PopupBox.prototype.__bgCSS = function()
{
    return {"width":$(document).width(),
	    "height":$(document).height(),
	    "position":"absolute",
	    "top":0,
	    "left":0,
	    "z-index":this.zIndex,
	    "opacity":this.bgOpacity,
	    "background-color":this.bgColor,
	    "display":"none"};
}

function WrapTag(tag,id,className,attr,innerHTML)
{
    if(!tag)
    {
	return null;
    }
    str = "<"+tag;
    if(id)
    {
	str+=" id='"+id+"'";
    }
    if(className)
    {
	str+=" class='"+className+"'";
    }
    if(attr)
	{
	    str+=" "+attr;
	}
    str+=">";
    if(innerHTML)
	str+=innerHTML;
    str+="</"+tag+">";
    return str;
}


/*class MessageBox
 *
 *just a globalMessageBox
 *
 *
 *
 *since version: 0.5
 *
 */
//instance
var messageBox = new MessageBox();
//class
function MessageBox()
{
}
MessageBox.prototype.box = new PopupBox("globalMessageBox","");
MessageBox.prototype.show = function(text)
{
    this.box.html(text);
    this.box.popup();
    var This = this;
    setTimeout(function(){This.box.popoff()},1200);
}
function Show(text){
    if(!messageBox)
    {
	messageBox = new MessageBox();
    }
    messageBox.box.zIndex = 1000;
    messageBox.box.width = 200;
    messageBox.box.height = 120;
    messageBox.show(text);
    $(messageBox.box.jqueryId).css({"background-color":"#FFFFFF","padding":50});
}